// pages/user_evaluate/user_evaluate.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,//当前页码
    perpage: 10,//数据条数
    totalpage:100,//总页码
    evaluateList: [],
    loadtips: '',
    loading:true
  },

  getEvaluateList: function (res) {
    var that = this;
    app.getLoginSession(function (session) {
      var act;
      if (that.data.options.from=='inside'){
        act='sys';
      }else{
        act='driver'
      }
      if (that.data.page <= that.data.totalpage){
        wx.request({
          url: app.api + '/wx_log_test/comment/' + act,
          data: {
            token: session,
            page: that.data.page,
            perpage: that.data.perpage,
          },
          success: function (res) {
            if (res.statusCode == 200) {
              if (res.data.msg == 'OK') {
                if (res.data.data.totalPages == 0) {
                  that.setData({
                    loadtips: '暂无相关评论',
                    loading:false
                  })
                } else {
                  that.setData({
                    evaluateList: that.data.evaluateList.concat(res.data.data.content),
                    totalpage: res.data.data.totalPages,
                    page: ++that.data.page,
                    loading:false
                  })
                  if(that.data.page-1==that.data.totalpage){
                    that.setData({
                      loadtips: '暂无更多评论'
                    })
                  }
                }
              } else {
                wx.showModal({
                  title: '提示',
                  content: res.data.msg,
                })
              }
            } else {
              wx.showModal({
                title: '提示',
                content: "接口返回错误，状态码：" + res.statusCode,
              })
            }
          }
        })
      }
      
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      options:options
    })
    this.getEvaluateList();
  },
  lower:function(res){
    var that = this;
    that.getEvaluateList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})